/*
 * Copyright (c) 2012 Sqpoll.
 * All rights reserved.
 */
package com.sqpoll.survey.model;

import java.io.Serializable;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * This class is a model for survey.
 * 
 * @author Younggue Bae
 */
@SuppressWarnings("serial")
public class Survey implements Serializable {

	private int surveyId;
	private String country;
	private String language;
	private String title;
	private String description;
	private String instruction;
	private String status;
	private String type;
	private String image;
	private String options;
	private String tags;
	private Date openDate;
	private Date closeDate;
	private String targetRule;
	private String publishChannel;
	private String style;
	private String sourceTemplate;
	private String owner;
	private String createUserId;
	private String updateUserId;
	private String deleteUserId;
	private Date createDate;
	private Date updateDate;
	private Date deleteDate;
	private boolean isDeleted;
	
	public int getSurveyId() {
		return surveyId;
	}
	public void setSurveyId(int surveyId) {
		this.surveyId = surveyId;
	}
	public String getCountry() {
		return country;
	}
	public void setCountry(String country) {
		this.country = country;
	}
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getInstruction() {
		return instruction;
	}
	public void setInstruction(String instruction) {
		this.instruction = instruction;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
	public String getOptions() {
		return options;
	}
	public void setOptions(String options) {
		this.options = options;
	}
	public String getTags() {
		return tags;
	}
	public void setTags(String tags) {
		this.tags = tags;
	}
	public Date getOpenDate() {
		return openDate;
	}
	public void setOpenDate(Date openDate) {
		this.openDate = openDate;
	}
	public Date getCloseDate() {
		return closeDate;
	}
	public void setCloseDate(Date closeDate) {
		this.closeDate = closeDate;
	}
	public String getTargetRule() {
		return targetRule;
	}
	public void setTargetRule(String targetRule) {
		this.targetRule = targetRule;
	}
	public String getPublishChannel() {
		return publishChannel;
	}
	public void setPublishChannel(String publishChannel) {
		this.publishChannel = publishChannel;
	}
	public String getStyle() {
		return style;
	}
	public void setStyle(String style) {
		this.style = style;
	}
	public String getSourceTemplate() {
		return sourceTemplate;
	}
	public void setSourceTemplate(String sourceTemplate) {
		this.sourceTemplate = sourceTemplate;
	}
	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public String getCreateUserId() {
		return createUserId;
	}
	public void setCreateUserId(String createUserId) {
		this.createUserId = createUserId;
	}
	public String getUpdateUserId() {
		return updateUserId;
	}
	public void setUpdateUserId(String updateUserId) {
		this.updateUserId = updateUserId;
	}
	public String getDeleteUserId() {
		return deleteUserId;
	}
	public void setDeleteUserId(String deleteUserId) {
		this.deleteUserId = deleteUserId;
	}
	public Date getCreateDate() {
		return createDate;
	}
	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}
	public Date getUpdateDate() {
		return updateDate;
	}
	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	public Date getDeleteDate() {
		return deleteDate;
	}
	public void setDeleteDate(Date deleteDate) {
		this.deleteDate = deleteDate;
	}
	public boolean isDeleted() {
		return isDeleted;
	}
	public void setDeleted(boolean isDeleted) {
		this.isDeleted = isDeleted;
	}
	
	public Survey toObject(String strJson) throws JSONException {
		JSONObject json = new JSONObject(strJson);

		if (json.has("surveyId"))	this.surveyId = json.getInt("surveyId");
		if (json.has("country"))	this.country = json.getString("country");
		if (json.has("language"))	this.language = json.getString("language");
		if (json.has("title"))	this.title = json.getString("title");
		if (json.has("description"))	this.description = json.getString("description");
		if (json.has("instruction"))	this.instruction = json.getString("instruction");
		if (json.has("status"))	this.status = json.getString("status");
		if (json.has("type"))	this.type = json.getString("type");
		if (json.has("image"))	this.image = json.getString("image");
		if (json.has("options"))	this.options = json.getString("options");
		if (json.has("tags"))	this.tags = json.getString("tags");
		//if (json.has("openDate"))	this.openDate = json.getString("openDate");
		//if (json.has("closeDate"))	this.closeDate = json.getString("closeDate");
		if (json.has("targetRule"))	this.targetRule = json.getString("targetRule");
		if (json.has("publishChannel"))	this.publishChannel = json.getString("publishChannel");
		if (json.has("style"))	this.style = json.getString("style");
		if (json.has("sourceTemplate"))	this.sourceTemplate = json.getString("sourceTemplate");
		if (json.has("owner"))	this.owner = json.getString("owner");
		if (json.has("createUserId"))	this.createUserId = json.getString("createUserId");
		if (json.has("updateUserId"))	this.updateUserId = json.getString("updateUserId");
		if (json.has("deleteUserId"))	this.deleteUserId = json.getString("deleteUserId");
		//if (json.has("createDate"))	this.createDate = json.getString("createDate");
		//if (json.has("updateDate"))	this.updateDate = json.getString("updateDate");
		//if (json.has("deleteDate"))	this.deleteDate = json.getString("deleteDate");
		if (json.has("isDeleted"))	this.isDeleted = json.getBoolean("isDeleted");
		
		return this;
	}
	
	public String toJson() {
		JSONObject json = new JSONObject(this);
		
		return json.toString();
	}
	
	@Override
	public String toString() {
		return "Survey [surveyId=" + surveyId + ", country=" + country + ", language=" + language + ", title=" + title
				+ ", description=" + description + ", instruction=" + instruction + ", status=" + status + ", type=" + type
				+ ", image=" + image + ", options=" + options + ", tags=" + tags + ", openDate=" + openDate + ", closeDate="
				+ closeDate + ", targetRule=" + targetRule + ", publishChannel=" + publishChannel + ", style=" + style
				+ ", sourceTemplate=" + sourceTemplate + ", owner=" + owner + ", createUserId=" + createUserId
				+ ", updateUserId=" + updateUserId + ", deleteUserId=" + deleteUserId + ", createDate=" + createDate
				+ ", updateDate=" + updateDate + ", deleteDate=" + deleteDate + ", isDeleted=" + isDeleted + "]";
	}

}
